package Offer003;

import java.util.ArrayList;
import java.util.List;

/**
 *  前 n 个数字二进制中 1 的个数
 * @author 23737
 * @time 2021.12.6
 */
public class Test {
    public static void main(String[] args) {

    }
}

class Solution {
    public int[] countBits(int n) {
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<=n; i++) {
            int number = Integer.bitCount(i);
            list.add(number);
        }
        int length = list.size();
        int[] result = new int[length];
        for(int i=0; i<length; i++) {
            result[i] = list.get(i);
        }
        return result;
    }
}
